﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Off_Day_Maintain.aspx.cs" ResponseEncoding="utf-8" MasterPageFile="~/MasterPage.master"
    Inherits="CallRoute_Off_Day_Maintain" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <title>无标题页</title>
    <link href='../resources/styles/divdialog.css' type="text/css" rel="stylesheet" />

    <script src="../JavaScript/common.js" type="text/javascript"></script>

  
    <script language="javascript" src="../Resources/scripts/SetOffDay.js" type="text/javascript">
    </script>

    <script language="javascript" type="text/javascript">
    
    function SingleCheck()
    {
        var obj = event.srcElement;
        if(obj.tagName=="INPUT" && obj.type=="checkbox")
        {
            if(obj.checked==true)
            {
                var chkedid=obj.id;
                //obj.nextSibling.innerText 所选复选框旁边的文本
                var inputs = document.getElementById("tree2").getElementsByTagName("input");
                for(var i=0;i<inputs.length;i++)
                {   
                    if((inputs[i].type=="checkbox") && (inputs[i].id != chkedid))
                    {
                        inputs[i].checked=false;
                    }
                }                
                UseCallBack("U"+obj.title);
            }
        }

    }
    
    function Cancel()
{
    // -----------隐藏'正在保存'-------------
      var back = document.getElementById("back");
      back.className = "";
      back.style.display="none";
}
 
     //判断是否是IE浏览器
    var Idx = 0;
    var IsIE;
    function fInitMSIE(){
            if (navigator.userAgent.indexOf("MSIE") != -1){
                    IsIE = true;
            }else{
                    IsIE = false;
            }
    }
    fInitMSIE();

    // 增加日期的函数，增加到 idDateSpan,基数为Idx 。
    function add(spanId) {

            addDate(spanId,Idx,"");
            Idx++;
            return false;
    }
    
    function loadDate(spanId)
    {
        //清除所有
        var dateSpan = document.getElementById(spanId);
        dateSpan.innerHTML="<span></span>";
        
        var hidValue = document.getElementById("txtholiday").value;
        var datevalues = hidValue.split(",");
        for(var i=0; i < datevalues.length; i++)
        {
            addDate(spanId,Idx,datevalues[i]);
            Idx++;            
        }
        return false;
    }
    
//---------------保存假日----------------

function saveDate()
{
//---------显示'正在保存'--------------------------
     var back = document.getElementById("back");
     back.className = "back";
     back.style.display="block"; 
//---------------------------------------------------
    var spanId = "";
    if(document.getElementById("RadOrg").checked){
        spanId = "idDateSpan";
        }
    else {
        spanId = "idDateSpan2";
        }
    //first,get the element
    var span = document.getElementById(spanId);
    if ( span == null ) { Cancel();return false;}
    
    var inputObjs = span.getElementsByTagName("input");
    if ( inputObjs == null ){ Cancel(); return false;}
    
    var DateValues = "";
    for(var i=0; i < inputObjs.length; i++)
    {
        if(inputObjs[i].type == "text")
        {
            if(inputObjs[i].value == "") 
            {
                alert('请选择放假日期!')
                Cancel();
                return false;
            }
            
            var date = inputObjs[i].value;   
                date = date.split("-");

            var date = new Date(parseInt(date[0],10),parseInt(date[1],10)-1,parseInt(date[2],10));

            var today = new Date();
            
            //var endDate = new Date(today.getFullYear(),today.getMonth() + 2, today.getDay());

            if(date<=today)
            {
                alert("请选择明天或以后的某一天!");
                Cancel();
                return false;
            }
            var collection = DateValues.split(",");
            if(collection.length>1)
            {
                for(var j=0; j < collection.length -1; j++)
                {
                    if(inputObjs[i].value == collection[j])
                    {
                        alert("您选择了重复的日期,请确认!");
                        Cancel();
                        return false;
                    }
                }
            }
                
            DateValues = DateValues + (inputObjs[i].value + ",");
        } 
    }
    
    if(spanId == "idDateSpan") //如果选择了组织维护
    {
        var OrgNames = ""; //组织结构名称
        var inputObjs = document.getElementById("OrgTree").getElementsByTagName("input");
            
        for(var i=0; i < inputObjs.length; i++)//遍历树获取选中节点
        {
            if(inputObjs[i].type == "checkbox")
            {
                if(inputObjs[i].checked)
                {
                    OrgNames = OrgNames+("'"+ inputObjs[i].title + "',");
                }
            }
         }
         if(OrgNames.length<1)
         {  
            alert('请选择组织结构!');
            Cancel();
            return false;
            }
         //
         UseCallBack(DateValues + "&" + OrgNames + "O");
      }
      
      if(spanId == "idDateSpan2")//如果选择了个人维护
      { 
         var mobileUserDDL = document.getElementById("ddlUserList");
         var userID = mobileUserDDL.options[mobileUserDDL.selectedIndex].value;
         if(userID=="0")
         {
            alert('请选择业代!');
            Cancel();
            return false;
            }
         //
         UseCallBack(DateValues + "&" + userID + "P");
      }
     
     //避免提交窗体
     return false;
}

function ShowHoliday(arg,context){
    Cancel();
       
     if(arg > 0)
     {
        alert('保存成功!');
     }
     else if(arg.toString().split('$')[0] == "SMUH")
     {
        document.getElementById("txtholiday").value=arg.toString().split('$')[1];
        loadDate("idDateSpan2");
     }
     else
     {
        var mobileUserDDL=document.getElementById("ddlUserList");
        mobileUserDDL.options.length = 0;
        var ListItems = arg.toString().split('$');
        var ListItem;
        //
        mobileUserDDL.options.add(new Option("---请选择---","0"));
        for(var i=0; i< ListItems.length; i++)
        {            
            ListItem = ListItems[i].split(',');
            if(ListItem[1]!=""&&ListItem[0]!="")
                mobileUserDDL.options.add(new Option(ListItem[1],ListItem[0]));
        }
        //showHolidayByMobileUser();
     }
 }
 //选择组织/个人
 function selectModel(Radio)
 {
    if(Radio.id=="RadOrg")
    {
        document.getElementById("tree1").style.display = "block";
        document.getElementById("tree2").style.display = "none";
        document.getElementById("OffDayOrg").style.display = "block";
        document.getElementById("OffDayUser").style.display = "none";
        document.getElementById("showUserList").style.display="none";
    }
    else if (Radio.id=="RadUser")
    {
        document.getElementById("tree2").style.display = "block";
        document.getElementById("tree1").style.display = "none";
        document.getElementById("OffDayUser").style.display = "block";
        document.getElementById("OffDayOrg").style.display = "none";
        document.getElementById("showUserList").style.display="block";        
    }
 }
 //选择业代,显示相应假日
 function showHolidayByMobileUser()
 {
    var mobileUserDDL = document.getElementById("ddlUserList");
    UseCallBack("M" + mobileUserDDL.options[mobileUserDDL.selectedIndex].value);
 }

    </script>


</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server" onload="loadDate('idDateSpan')">
    <div id="OrgTree" style="float: left; width: 100%;">
        <input type="hidden" id="txtholiday" runat="server" />
        <table id="wsd_inputtable">
            <tr colspan="10">
                <td class="tabletitle" style="height: 21px" width="100%">
                    组织结构树状视图&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 组织<input type="radio" id="RadOrg" onclick="selectModel(this);" checked="checked" name="1" />
                    <input type="radio" id="RadUser" onclick="selectModel(this);" name="1" />个人
                </td>
            </tr>
        </table>
        <table id="wsd_listtable">
            <tr>
                <td>
                    <div style="height: 200px; width: 100%; overflow: auto">
                        <div id="tree1">
                            <asp:TreeView ID="TreeOrg" runat="server" ShowLines="True" OnSelectedNodeChanged="TreeOrg_SelectedNodeChanged">
                            </asp:TreeView>
                        </div>
                        <div id="tree2" style="display: none;">
                            <asp:TreeView ID="TreeOrg2" runat="server" ShowLines="True" OnSelectedNodeChanged="TreeOrg_SelectedNodeChanged">
                            </asp:TreeView>
                        </div>
                    </div>
                </td>
            </tr>
        </table>
    </div>
    <div id="holiday">
        <table id="wsd_inputtable">
            <tr>
                <td class="tabletitle" style="height: 21px;" width="70%">
                    放假日期设置
                </td>
                <td class="tabletitle" style="padding: 0; margin: 0;">
                    <div id="showUserList" style="display: none; padding: 0; margin: 0;">
                        业代:
                        <select id="ddlUserList" onchange="showHolidayByMobileUser()">
                        </select>
                    </div>
                </td>
            </tr>
        </table>
        <table id="wsd_listtable">
            <tr>
                <td style="width: 100%;">
                    <div style="height: 150px; width: 99%; overflow: auto">
                        <br />
                        <div id="OffDayOrg">
                            <span id="idDateSpan"></span><a id="Date" title="如果您要设置多个放假日期，您只需多次点击“添加假日”即可, 请不要选择已过去的时间。"
                                onclick="add('idDateSpan');this.childNodes[0].nodeValue='继续添加假日';" href="javascript:;"
                                name="Date" style="font-size: 12pt; color: Red; font-weight: bolder;">添加假日</a>
                        </div>
                        <div id="OffDayUser" style="display: none;">
                            <span id="idDateSpan2"></span><a id="A1" title="如果您要设置多个放假日期，您只需多次点击“添加假日”即可, 请不要选择已过去的时间。"
                                onclick="add('idDateSpan2');this.childNodes[0].nodeValue='继续添加假日';" href="javascript:;"
                                name="Date" style="font-size: 12pt; color: Red; font-weight: bolder;">添加假日</a>
                        </div>
                    </div>
                </td>
            </tr>
        </table>
    </div>
    <table id="wsd_inputtable" style="margin-top: 10px;">
        <tr>
            <td width="100%" class="tabletitle">
                <asp:Literal ID="Literal40" runat="server" Text="<%$resources:language,lbl_Operation_Area %>"></asp:Literal>
            </td>
        </tr>
        <tr>
            <td class="buttonarea">
                <asp:Button ID="btnSave" runat="server" OnClientClick="return saveDate();" class="wsd_button2"
                    Text="保 存" />
            </td>
        </tr>
    </table>
    <div id="back" style="text-align: center; display: none;">
        <p style="height: 45%;">
        </p>
        正在保存...
    </div>
</asp:Content>
